package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.model.entity.RoomPaymentType;
import com.atguigu.lease.web.app.mapper.PaymentTypeMapper;
import com.atguigu.lease.web.app.mapper.RoomPaymentTypeMapper;
import com.atguigu.lease.web.app.service.PaymentTypeService;
import com.atguigu.lease.web.app.service.RoomPaymentTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【payment_type(支付方式表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class PaymentTypeServiceImpl extends ServiceImpl<PaymentTypeMapper, PaymentType>
    implements PaymentTypeService{

    @Autowired
    private RoomPaymentTypeMapper roomPaymentTypeMapper;

    @Override
    public List<PaymentType> getListPaymentTypeByRoomId(Long roomId) {
        QueryWrapper<RoomPaymentType> roomPaymentTypeQueryWrapper = new QueryWrapper<>();
        roomPaymentTypeQueryWrapper.eq("room_id", roomId);
        List<RoomPaymentType> roomPaymentTypes = roomPaymentTypeMapper.selectList(roomPaymentTypeQueryWrapper);
        List<PaymentType> paymentTypes = new ArrayList<>();
        for (RoomPaymentType roomPaymentType : roomPaymentTypes) {
            Long paymentTypeId = roomPaymentType.getPaymentTypeId();
            PaymentType paymentType = baseMapper.selectById(paymentTypeId);
            paymentTypes.add(paymentType);
        }

        return paymentTypes;
    }
}




